﻿using System.Collections.Generic;

namespace Interactive.Utility.Collections
{
    /// <summary>
    /// 任意两个比较的值不会相等。较后插入的值将视为较大。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    internal class NoEqualComparer<T> : IComparer<T>
    {
        private readonly IComparer<T> compare;

        /// <param name="compare">该值为空时使用默认比较器</param>
        public NoEqualComparer(IComparer<T> compare)
        {
            this.compare = compare ?? Comparer<T>.Default;
        }

        #region IComparer<T> Members

        public int Compare(T x, T y)
        {
            return compare.Compare(x, y) >= 0 ? 1 : -1;
        }

        #endregion
    }
}